package com.example.smartcity_ikun3.ui.Smart.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.smartcity_ikun3.R
import com.example.smartcity_ikun3.logic.util.Util.show
import com.example.smartcity_ikun3.ui.Smart.model.SmListEntity
import com.example.smartcity_ikun3.ui.Smart.model.SmartSmartActivity
import kotlinx.android.synthetic.main.re_smart_item_list.*

class SmartListRecyclerViewAdapter (
    val data: List<SmListEntity>
) : RecyclerView.Adapter<SmartListRecyclerViewAdapter.ViewHolder>(){
    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        val setImage: ImageView = view.findViewById(R.id.SmImageView)
        val setTitle: TextView = view.findViewById(R.id.SmTitle)
        val setContent: TextView = view.findViewById(R.id.SmContent)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.re_smart_item_list, parent, false)
        val view = ViewHolder(root)

        view.itemView.setOnClickListener {
            if (view.setTitle.text == "同辉养老") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm1.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })

            if (view.setTitle.text == "赣州幸福村智慧养老平台") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm2.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })

            if (view.setTitle.text == "佳林养老院") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm3.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })

            if (view.setTitle.text == "河北枫叶老年公寓") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm4.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })


            if (view.setTitle.text == "石家庄藁城区盛德老年公寓") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm5.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })

            if (view.setTitle.text == "新华区银龄老年公寓") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm6.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })

            if (view.setTitle.text == "金秋阳光养老产业园") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm6.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })

            if (view.setTitle.text == "示范型居家养老服务中心") parent.context.startActivity(Intent(parent.context, SmartSmartActivity::class.java).apply {
                putExtra("imageView", R.mipmap.sm7.toString())
                putExtra("title", view.setTitle.text)
                putExtra("content", view.setContent.text)
            })
        }



        return view
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val list = data[position]
        holder.setImage.setImageResource(list.getImg)
        holder.setTitle.text = list.getTitle
        holder.setContent.text = list.getContent
    }


}